/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package energyanalyzer;

import datafactory.AutoDockDataReader;
import datafactory.VinaDataReader;
import datastructures.*;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.File;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Iterator;
import java.util.Locale;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author paolo
 */
public class EAFrame extends javax.swing.JFrame {
    
    private File lastPath;
    private AutoDockData autoDockData;
    private VinaData vinaData;
    
    /**
     * Creates new form EAFrame
     */
    public EAFrame() {
        lastPath = null;
        autoDockData = null;
        vinaData = null;
        
        initComponents();
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((dim.width - getSize().width) / 2, (dim.height - getSize().height) / 2); 
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        infoDialog = new javax.swing.JDialog(this, "Input file formats", true);
        infoLabel = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        parametersPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        rmsSelection = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        calculateButton = new javax.swing.JButton();
        loadingIcon = new javax.swing.JLabel();
        resultsPanel = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        energyTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        constantTextField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        autoDockMenu = new javax.swing.JMenu();
        autoDockClusterMenuItem = new javax.swing.JMenuItem();
        autoDockExclusionMenuItem = new javax.swing.JMenuItem();
        vinaMenu = new javax.swing.JMenu();
        vinaLogMenuItem = new javax.swing.JMenuItem();
        vinaExclusionMenuItem = new javax.swing.JMenuItem();
        fileMenuSeparator = new javax.swing.JPopupMenu.Separator();
        exitMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        infoMenuItem = new javax.swing.JMenuItem();
        helpMenuSeparator = new javax.swing.JPopupMenu.Separator();
        aboutMenuItem = new javax.swing.JMenuItem();

        infoDialog.setResizable(false);
        infoDialog.setSize(460, 390);
        infoDialog.setLocationRelativeTo(this);

        infoLabel.setText("<html>   <b>AutoDock cluster data:</b><br>   Open your docking result with AutoDock Tools.<br>Select Analyze > Cluster > Recluster...<br>   Input a space separated list of desired RMS tollerances and save it to a file.<br><br>   <b>AutoDock exclusion list:</b><br>   Create a text file with a line for each desired RMS tollerance.<br>   The first field has to be the RMS tollerance followed by a semicolon.<br>   Next to that write a space separated list of those cluster numbers to exclude.<br>   <i>Example:</i><br>   0.5: 6 9 12<br>   2.0: 1 6<br><br>   <b>Vina log file:</b><br>   Just open the log outcome of the Vina docking run.<br><br>   <b>Vina exclusion list:</b><br>   Create a text file with just one line.<br>   Write a space separated list of those modes to exclude.<br>   <i>Example:</i><br>   1 7 16 5</html>");

        jButton1.setText("OK");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout infoDialogLayout = new javax.swing.GroupLayout(infoDialog.getContentPane());
        infoDialog.getContentPane().setLayout(infoDialogLayout);
        infoDialogLayout.setHorizontalGroup(
            infoDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(infoDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(infoDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(infoDialogLayout.createSequentialGroup()
                        .addComponent(infoLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, infoDialogLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        infoDialogLayout.setVerticalGroup(
            infoDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(infoDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(infoLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Energy Analyzer");
        setIconImage(new ImageIcon (getClass().getResource("/data/icon.png")).getImage());
        setResizable(false);

        parametersPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters"));

        jLabel1.setText("RMS Tollerance:");

        rmsSelection.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0.0" }));

        jLabel6.setText("(0.0 for arithmetic mean)");

        calculateButton.setText("Calculate!");
        calculateButton.setEnabled(false);
        calculateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                calculateButtonActionPerformed(evt);
            }
        });

        loadingIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/data/loading.gif"))); // NOI18N
        loadingIcon.setVisible(false);

        javax.swing.GroupLayout parametersPanelLayout = new javax.swing.GroupLayout(parametersPanel);
        parametersPanel.setLayout(parametersPanelLayout);
        parametersPanelLayout.setHorizontalGroup(
            parametersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(parametersPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(parametersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(calculateButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(rmsSelection, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(parametersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(loadingIcon))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        parametersPanelLayout.setVerticalGroup(
            parametersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(parametersPanelLayout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addGroup(parametersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(rmsSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(parametersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(calculateButton, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, parametersPanelLayout.createSequentialGroup()
                        .addComponent(loadingIcon)
                        .addContainerGap())))
        );

        resultsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Results"));

        jLabel2.setText("Free Energy:");

        energyTextField.setEditable(false);

        jLabel3.setText("Binding Constant:");

        constantTextField.setEditable(false);

        jLabel4.setText("Kcal");

        jLabel5.setText("<html>M<sup>-1</sup></html>");

        javax.swing.GroupLayout resultsPanelLayout = new javax.swing.GroupLayout(resultsPanel);
        resultsPanel.setLayout(resultsPanelLayout);
        resultsPanelLayout.setHorizontalGroup(
            resultsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(resultsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(resultsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(resultsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(energyTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
                    .addComponent(constantTextField))
                .addGap(18, 18, 18)
                .addGroup(resultsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        resultsPanelLayout.setVerticalGroup(
            resultsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(resultsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(resultsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(energyTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(resultsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(constantTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        fileMenu.setText("File");

        autoDockMenu.setText("Autodock");

        autoDockClusterMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        autoDockClusterMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/data/open.png"))); // NOI18N
        autoDockClusterMenuItem.setText("Open cluster file...");
        autoDockClusterMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                autoDockClusterMenuItemActionPerformed(evt);
            }
        });
        autoDockMenu.add(autoDockClusterMenuItem);

        autoDockExclusionMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/data/list.png"))); // NOI18N
        autoDockExclusionMenuItem.setText("Open exclusion list...");
        autoDockExclusionMenuItem.setEnabled(false);
        autoDockExclusionMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                autoDockExclusionMenuItemActionPerformed(evt);
            }
        });
        autoDockMenu.add(autoDockExclusionMenuItem);

        fileMenu.add(autoDockMenu);

        vinaMenu.setText("Vina");

        vinaLogMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        vinaLogMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/data/open.png"))); // NOI18N
        vinaLogMenuItem.setText("Open log file...");
        vinaLogMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vinaLogMenuItemActionPerformed(evt);
            }
        });
        vinaMenu.add(vinaLogMenuItem);

        vinaExclusionMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/data/list.png"))); // NOI18N
        vinaExclusionMenuItem.setText("Open exclusion list...");
        vinaExclusionMenuItem.setEnabled(false);
        vinaExclusionMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vinaExclusionMenuItemActionPerformed(evt);
            }
        });
        vinaMenu.add(vinaExclusionMenuItem);

        fileMenu.add(vinaMenu);
        fileMenu.add(fileMenuSeparator);

        exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        exitMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/data/exit.png"))); // NOI18N
        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText("Help");

        infoMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK));
        infoMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/data/info.png"))); // NOI18N
        infoMenuItem.setText("Input file formats");
        infoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                infoMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(infoMenuItem);
        helpMenu.add(helpMenuSeparator);

        aboutMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/data/about.png"))); // NOI18N
        aboutMenuItem.setText("About...");
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(resultsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(parametersPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(parametersPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16)
                .addComponent(resultsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        setVisible(false);
        dispose();
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed
    
    private void autoDockClusterMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoDockClusterMenuItemActionPerformed
        File file;
        JFileChooser open = new JFileChooser();
        
        open.setDialogTitle("Open");
        open.setDialogType(JFileChooser.OPEN_DIALOG);
        if (lastPath != null) {
            open.setCurrentDirectory(lastPath);
        }
        
        loadingIcon.setVisible(true);
        
        if (open.showOpenDialog(this) == JFileChooser.APPROVE_OPTION &&
                (file = open.getSelectedFile()) != null) {
            
            lastPath = file.getParentFile();
            autoDockData = AutoDockDataReader.readClusterData(file);
            
            rmsSelection.removeAllItems();
            rmsSelection.addItem("0.0");
            Iterator<RMS> iter = autoDockData.getRMSs().iterator();
            float rmsValue;
            while (iter.hasNext()) {
                if ((rmsValue = iter.next().getValue()) != 0.0f) {
                  rmsSelection.addItem(String.valueOf(rmsValue));
                }
            }
            
            vinaData = null;
            vinaExclusionMenuItem.setEnabled(false);
            autoDockExclusionMenuItem.setEnabled(true);
            calculateButton.setEnabled(true);
            energyTextField.setText("");
            constantTextField.setText("");
        }
        
        loadingIcon.setVisible(false);
    }//GEN-LAST:event_autoDockClusterMenuItemActionPerformed

    private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calculateButtonActionPerformed
        loadingIcon.setVisible(true);
        
        if (autoDockData != null) {
            rmsSelection.setEnabled(false);
            autoDockClusterMenuItem.setEnabled(false);
            autoDockExclusionMenuItem.setEnabled(false);
            vinaLogMenuItem.setEnabled(false);
            vinaExclusionMenuItem.setEnabled(false);
            calculateButton.setEnabled(false);
            
            float rmsValue = Float.parseFloat((String) rmsSelection.getSelectedItem());
            Iterator<Cluster> iter = autoDockData.getRMS(rmsValue).getClusters().iterator();
            Cluster cluster;
            int count = 0;
            float sum = 0.0f, constant;
            while (iter.hasNext()) {
                cluster = iter.next();
                if (cluster.isEnabled()) {
                    if (rmsValue == 0.0f) {
                        Iterator<Float> iter2 = cluster.getEnergies().iterator();
                        while (iter2.hasNext()) {
                            sum += iter2.next();
                        }
                    }
                    else {
                        sum += cluster.getEnergies().get(0) * cluster.getSize();
                    }
                    count += cluster.getSize();
                }
            }
            
            sum /= count;
            constant = (float) Math.exp(-((sum * 4184) / (8.314472 * 298)));
            
            NumberFormat nf = NumberFormat.getInstance();
            nf.setMaximumFractionDigits(3);
            energyTextField.setText(nf.format(sum));
            nf = new DecimalFormat("0.0E0");
            constantTextField.setText(nf.format(constant));
            
            rmsSelection.setEnabled(true);
            autoDockClusterMenuItem.setEnabled(true);
            autoDockExclusionMenuItem.setEnabled(true);
            vinaLogMenuItem.setEnabled(true);
            calculateButton.setEnabled(true);
        }
        else if (vinaData != null) {
            rmsSelection.setEnabled(false);
            autoDockClusterMenuItem.setEnabled(false);
            autoDockExclusionMenuItem.setEnabled(false);
            vinaLogMenuItem.setEnabled(false);
            vinaExclusionMenuItem.setEnabled(false);
            calculateButton.setEnabled(false);
            
            int count = 0;
            float sum = 0.0f, constant;
            Conformation conf;
            Iterator<Conformation> iter = vinaData.getConformations().iterator();
            
            while (iter.hasNext()) {
                conf = iter.next();
                
                if (conf.isEnabled()) {
                    count++;
                    sum += conf.getEnergy();
                }
            }
            sum /= count;
            
            constant = (float) Math.exp(-((sum * 4184) / (8.314472 * 298)));
            
            NumberFormat nf = NumberFormat.getInstance();
            nf.setMaximumFractionDigits(3);
            energyTextField.setText(nf.format(sum));
            nf = new DecimalFormat("0.0E0");
            constantTextField.setText(nf.format(constant));
            
            rmsSelection.setEnabled(true);
            autoDockClusterMenuItem.setEnabled(true);
            autoDockExclusionMenuItem.setEnabled(false);
            vinaLogMenuItem.setEnabled(true);
            vinaExclusionMenuItem.setEnabled(true);
            calculateButton.setEnabled(true);
        }
        else {
            autoDockExclusionMenuItem.setEnabled(false);
            vinaExclusionMenuItem.setEnabled(false);
            calculateButton.setEnabled(false);
            rmsSelection.removeAllItems();
            rmsSelection.addItem("0.0");
            energyTextField.setText("");
            constantTextField.setText("");
            JOptionPane.showMessageDialog(this, "Nothing to do, apparently...", "WARNING!", JOptionPane.WARNING_MESSAGE);
        }
        
        loadingIcon.setVisible(false);
    }//GEN-LAST:event_calculateButtonActionPerformed

    private void vinaLogMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vinaLogMenuItemActionPerformed
        File file;
        JFileChooser open = new JFileChooser();
        
        open.setDialogTitle("Open");
        open.setDialogType(JFileChooser.OPEN_DIALOG);
        if (lastPath != null) {
            open.setCurrentDirectory(lastPath);
        }
        
        loadingIcon.setVisible(true);
        
        if (open.showOpenDialog(this) == JFileChooser.APPROVE_OPTION &&
                (file = open.getSelectedFile()) != null) {
            
            lastPath = file.getParentFile();
            vinaData = VinaDataReader.readVinaData(file);
            
            autoDockData = null;
            rmsSelection.removeAllItems();
            rmsSelection.addItem("0.0");
            
            vinaExclusionMenuItem.setEnabled(true);
            autoDockExclusionMenuItem.setEnabled(false);
            calculateButton.setEnabled(true);
            energyTextField.setText("");
            constantTextField.setText("");
        }
        
        loadingIcon.setVisible(false);
    }//GEN-LAST:event_vinaLogMenuItemActionPerformed

    private void autoDockExclusionMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_autoDockExclusionMenuItemActionPerformed
        File file;
        JFileChooser open = new JFileChooser();
        
        open.setDialogTitle("Open");
        open.setDialogType(JFileChooser.OPEN_DIALOG);
        if (lastPath != null) {
            open.setCurrentDirectory(lastPath);
        }
        
        loadingIcon.setVisible(true);
        
        if (open.showOpenDialog(this) == JFileChooser.APPROVE_OPTION &&
                (file = open.getSelectedFile()) != null) {
            
            lastPath = file.getParentFile();
            AutoDockDataReader.readExclusionList(file, autoDockData);
        }
        
        loadingIcon.setVisible(false);
    }//GEN-LAST:event_autoDockExclusionMenuItemActionPerformed

    private void vinaExclusionMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vinaExclusionMenuItemActionPerformed
        File file;
        JFileChooser open = new JFileChooser();
        
        open.setDialogTitle("Open");
        open.setDialogType(JFileChooser.OPEN_DIALOG);
        if (lastPath != null) {
            open.setCurrentDirectory(lastPath);
        }
        
        loadingIcon.setVisible(true);
        
        if (open.showOpenDialog(this) == JFileChooser.APPROVE_OPTION &&
                (file = open.getSelectedFile()) != null) {
            
            lastPath = file.getParentFile();
            VinaDataReader.readExclusionList(file, vinaData);
        }
        
        loadingIcon.setVisible(false);
    }//GEN-LAST:event_vinaExclusionMenuItemActionPerformed

    private void infoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_infoMenuItemActionPerformed
        infoDialog.setVisible(true);
    }//GEN-LAST:event_infoMenuItemActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
        String message = "\n   Energy Analyzer\n" +
                         "     Version 1.0\n\n" + 
                         "© 2012 - Paolo Gatti\n" +
                         "n3o.eden@gmail.com";
        JOptionPane.showMessageDialog(this, message, "About...", JOptionPane.PLAIN_MESSAGE,
                new ImageIcon(getClass().getResource("/data/aboutImg.png")));
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        infoDialog.setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
        * Set the Nimbus look and feel
        */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
        * If Nimbus (introduced in Java SE 6) is not available, stay with the
        * default look and feel. For details see
        * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
        */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EAFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EAFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EAFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EAFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
        * Create and display the form
        */

        Locale.setDefault(Locale.US);
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new EAFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JMenuItem autoDockClusterMenuItem;
    private javax.swing.JMenuItem autoDockExclusionMenuItem;
    private javax.swing.JMenu autoDockMenu;
    private javax.swing.JButton calculateButton;
    private javax.swing.JTextField constantTextField;
    private javax.swing.JTextField energyTextField;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JPopupMenu.Separator fileMenuSeparator;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JPopupMenu.Separator helpMenuSeparator;
    private javax.swing.JDialog infoDialog;
    private javax.swing.JLabel infoLabel;
    private javax.swing.JMenuItem infoMenuItem;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel loadingIcon;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JPanel parametersPanel;
    private javax.swing.JPanel resultsPanel;
    private javax.swing.JComboBox rmsSelection;
    private javax.swing.JMenuItem vinaExclusionMenuItem;
    private javax.swing.JMenuItem vinaLogMenuItem;
    private javax.swing.JMenu vinaMenu;
    // End of variables declaration//GEN-END:variables
}
